package com.chinasofti.udp;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
public class ReceiveDemo {
    public static void main(String[] args) throws IOException {
        //创建发送端的Socket对象
        DatagramSocket ds = new DatagramSocket();

        //创建一个数据包，用于接收数据
        byte[] bys = new byte[1024];
        //DatagramPacket(byte[] buf, int length, SocketAddress address)
        DatagramPacket dp = new DatagramPacket(bys,bys.length);

        //调用DatagramSocket   receive(DatagramPacket p)
        ds.receive(dp);//从套接字接收数据包

        System.out.println("数据是：" + new String(dp.getData(),0,dp.getLength()));
    }
}